from django.utils import timezone
from rest_framework import serializers
from .models import OncallInfo


class OncallInfoSerializer(serializers.ModelSerializer):
    start_time = serializers.DateTimeField(format='%Y-%m-%d')    #format='%Y-%m-%d %H:%M:%S', required=False, read_only=True
    end_time = serializers.DateTimeField(format='%Y-%m-%d')      #format='%Y-%m-%d %H:%M:%S'
    dev_name = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = OncallInfo
        fields = ['id', 'dev_group',  "dev_name", 'oncaller', 'time']

    # def get_time(self, obj):90
    #     if obj:
    #        time = {obj.start_time, obj.end_time}
    #        return time

    def get_dev_name(self, obj):
        if obj:
            return obj.dev_group.team_name




